package com.gitee.wsl.compose.chart.polar.axis

import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import com.gitee.wsl.unit.angle.AngleUnit
import com.gitee.wsl.unit.angle.PolarAngleDirection
import com.gitee.wsl.unit.angle.PolarAngleZero
import com.gitee.wsl.unit.angle.rad
import kotlin.math.PI

/**
 * An [AngularAxisModel] that uses [AngleUnit]s of either Radians or Degrees.
 *
 * @param tickValues The angular value of each tick that should be drawn on the plot.
 */
 data class AngularValueAxisModel(
    private val tickValues: List<AngleUnit> = buildList {
        @Suppress("MagicNumber")
        for (i in 0..<8) {
            add((PI * i / 4.0).rad)
        }
    },
    override val polarAngleDirection: PolarAngleDirection = PolarAngleDirection.COUNTERCLOCKWISE,
    override val polarAngleZero: PolarAngleZero = PolarAngleZero.THREE_OCLOCK
) : AngularAxisModel<AngleUnit> {
    override fun getTickValues(): List<AngleUnit> = tickValues

    override fun computeOffset(point: AngleUnit): AngleUnit = point
}

@Composable
 fun rememberAngularValueAxisModel(
    tickValues: List<AngleUnit> = buildList {
        @Suppress("MagicNumber")
        for (i in 0..<8) {
            add((PI * i / 4.0).rad)
        }
    },
    polarAngleDirection: PolarAngleDirection = PolarAngleDirection.COUNTERCLOCKWISE,
    polarAngleZero: PolarAngleZero = PolarAngleZero.THREE_OCLOCK
): AngularValueAxisModel =
    remember(tickValues, polarAngleDirection, polarAngleZero) {
        AngularValueAxisModel(
            tickValues,
            polarAngleDirection,
            polarAngleZero
        )
    }

@Composable
fun <T> AngularAxisModel.Companion.Angular( tickValues: List<AngleUnit> = buildList {
                                                     @Suppress("MagicNumber")
                                                     for (i in 0..<8) {
                                                         add((PI * i / 4.0).rad)
                                                     }
                                                 },
                                            polarAngleDirection: PolarAngleDirection = PolarAngleDirection.COUNTERCLOCKWISE,
                                            polarAngleZero: PolarAngleZero = PolarAngleZero.THREE_OCLOCK)
= rememberAngularValueAxisModel(tickValues, polarAngleDirection, polarAngleZero)